<?php

use App\Http\Controllers\PayNotifyController;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\WeChat\LoginController;
use App\WeChat\BindController;
use App\WeChat\ApiController;
use App\Api\AuthController;
//网站主页
Route::get('/', function () {
    if ($module = site('module')) {
        \ModuleService::cache($module);
        return app("Modules\\{$module['name']}\Http\Controllers\HomeController")->home();
    }
    abort(404);
})->name('home');

//支付通知
Route::group(['prefix' => 'pay/{module}'], function () {
    Route::any('alipay/return', [PayNotifyController::class, 'alipayReturn'])->name('pay.alipay.return');
    Route::any('alipay/notify', [PayNotifyController::class, 'alipayNotify'])->name('pay.alipay.notify');
    //native微信支付
    Route::any('wepay/notify', [PayNotifyController::class, 'wepayNotify'])->name('pay.wepay.notify');
});

//模块后台
Route::get("{module}/admin", function ($module) {
    return redirect($module . '/site/' . site('id') . '/admin');
});

//微信相关
Route::group(['prefix' => 'wechat'], function () {
    //登录授权
    Route::get('login', [LoginController::class, 'login']);
    //绑定微信
    Route::get('bind', [BindController::class, 'bind']);
});

//微信公众号接口
Route::any('wechat/api/{site}/{model}', [ApiController::class, 'handle']);

//退出登录
Route::get('logout', [AuthController::class, 'logout']);

//系统应用
Route::get('{app}/{path?}', function () {
    return view('app');
})->where('app', 'system|admin|member|site|login|register|wechat|mini|forget')->where('path', '.*');
